package com.bree.erp.entity;

import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
public class Address {

	public static final int COL_CONTACTPERSON_LEN = 50;
	public static final int COL_NUMBER_LEN = 50;
	public static final int COL_STREET_LEN = 150;
	public static final int COL_BARANGAY_LEN = 100;
	public static final int COL_BUILDING_LEN = 100;
	public static final int COL_DISTRICT_LEN = 100;
	public static final int COL_CITY_LEN = 50;
	public static final int COL_PROVINCE_LEN = 50;
	public static final int COL_COUNTRY_LEN = 50;
	public static final int COL_ZIP_LEN = 10;
	
	@Column(length=COL_CONTACTPERSON_LEN)
	private String contactPerson;
	@Column(length=COL_NUMBER_LEN)
	private String number;
	@Column(length=COL_STREET_LEN)
	private String street;
	@Column(length=COL_BUILDING_LEN)
	private String building;
	@Column(length=COL_BARANGAY_LEN)
	private String barangay;
	@Column(length=COL_DISTRICT_LEN)
	private String district;
	@Column(length=COL_CITY_LEN)
	private String city;
	@Column(length=COL_PROVINCE_LEN)
	private String province;
	@Column(length=COL_COUNTRY_LEN)
	private String country;
	@Column(length=COL_ZIP_LEN)
	private String zip;

	@Override
	public String toString() {

		StringBuilder sb = new StringBuilder();

		String prefix = "";
		String[] items = { number, street, building, barangay, district, city, province,
				country, zip };

		for (String item : items) {
			if (notEmpty(item)) {
				sb.append(prefix);
				sb.append(item);
				prefix = " ";
			}
		}

		return sb.toString();
	}

	private boolean notEmpty(String value) {
		return (value != null && value.trim().length() > 0);
	}

	/**
	 * @return the number
	 */
	public String getNumber() {
		return number;
	}

	/**
	 * @param number
	 *            the number to set
	 */
	public void setNumber(String number) {
		this.number = number;
	}

	/**
	 * @return the street
	 */
	public String getStreet() {
		return street;
	}

	/**
	 * @param street
	 *            the street to set
	 */
	public void setStreet(String street) {
		this.street = street;
	}

	/**
	 * @return the barangay
	 */
	public String getBarangay() {
		return barangay;
	}

	/**
	 * @param barangay
	 *            the barangay to set
	 */
	public void setBarangay(String barangay) {
		this.barangay = barangay;
	}

	/**
	 * @return the district
	 */
	public String getDistrict() {
		return district;
	}

	/**
	 * @param district
	 *            the district to set
	 */
	public void setDistrict(String district) {
		this.district = district;
	}

	/**
	 * @return the city
	 */
	public String getCity() {
		return city;
	}

	/**
	 * @param city
	 *            the city to set
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * @return the province
	 */
	public String getProvince() {
		return province;
	}

	/**
	 * @param province
	 *            the province to set
	 */
	public void setProvince(String province) {
		this.province = province;
	}

	/**
	 * @return the country
	 */
	public String getCountry() {
		return country;
	}

	/**
	 * @param country
	 *            the country to set
	 */
	public void setCountry(String country) {
		this.country = country;
	}

	/**
	 * @return the zip
	 */
	public String getZip() {
		return zip;
	}

	/**
	 * @param zip
	 *            the zip to set
	 */
	public void setZip(String zip) {
		this.zip = zip;
	}

	/**
	 * @return the contactPerson
	 */
	public String getContactPerson() {
		return contactPerson;
	}

	/**
	 * @param contactPerson the contactPerson to set
	 */
	public void setContactPerson(String contactPerson) {
		this.contactPerson = contactPerson;
	}

	/**
	 * @return the building
	 */
	public String getBuilding() {
		return building;
	}

	/**
	 * @param building the building to set
	 */
	public void setBuilding(String building) {
		this.building = building;
	}

}
